package com.zd.commodity.productMng.dao.impl;

import javax.annotation.Resource;

import org.hibernate.SessionFactory;
import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.MatchMode;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Repository;

import com.zd.commodity.dao.impl.BaseDao;
import com.zd.commodity.productMng.dao.IProductPriceCalculateDao;
import com.zd.commodity.productMng.entity.ProductPriceCalculate;


@Repository("productPriceCalculateDao")
public class ProductPriceCalculateDaoImpl extends BaseDao<ProductPriceCalculate> implements
		IProductPriceCalculateDao {

	@Resource(name = "sessionFactory")
	public void setSuperSessionFactory(SessionFactory sessionFactory){
		super.setSessionFactory(sessionFactory);
	}
	
	@Override
	public DetachedCriteria getDetachedCriteria(ProductPriceCalculate t1,ProductPriceCalculate t2,Object params){
		DetachedCriteria dc=DetachedCriteria.forClass(ProductPriceCalculate.class);
		if(t1!=null){
			if(t1.getProduct()!=null){
				if(t1.getProduct().getName()!=null && !t1.getProduct().getName().equals("")){
					dc.createAlias("product", "p");
					dc.add(Restrictions.like("p.name", t1.getProduct().getName(), MatchMode.ANYWHERE));
				}
				if(t1.getSupplier().getName()!=null && !t1.getSupplier().getName().equals("")){
					dc.createAlias("supplier", "s");
					dc.add(Restrictions.like("s.name", t1.getSupplier().getName(), MatchMode.ANYWHERE));
				}
			}
		}
		return dc;
	}
}
